package mmc;

import java.io.IOException;

import mmc.stats.StandardStats;
import mmc.stats.Stats;

@SuppressWarnings("serial")
abstract public class MovableEngineObject extends EngineObject{
	
	public MovableEngineObject(int id, float x, float y, float z, float vx, float vy, float vz){
		this(id, x,y,z);
		this.vx = vx;
		this.vy = vy;
		this.vz = vz;
	}
	
	public MovableEngineObject(float x, float y, float z, float vx, float vy, float vz){
		this(x,y,z);
		this.vx = vx;
		this.vy = vy;
		this.vz = vz;
	}
	
	public MovableEngineObject(float x, float y, float z){
		super(x,y,z);
	}
	
	public MovableEngineObject(int id, float x, float y, float z){
		super(id, x,y,z);
	}
	
	public float vx, vy, vz;
	public int target = -1;
	public Stats stats = new Stats(this);
	
	@Override
	public void modifyStat(String name, int absolute, int percental){
		stats.modifyActualValue(name, absolute, percental);
		this.dirty = true;
	}
	
	@Override
	public boolean isDead(){
		if(stats.getValue(StandardStats.HP) <= 1){
			return true;
		}
		else{
			return false;
		}
	}
	
	protected void copyFieldsTo(MovableEngineObject o){
		o.x = x;
		o.y = y;
		o.z = z;
		o.vx = vx;
		o.vy = vy;
		o.vz = vz;
		o.health = health;
		o.energy = energy;
		o.target = target;
		o.stats = stats;
	}
	
	public boolean dataEquals(MovableEngineObject o){
		return x == o.x && y == o.y && z == o.z && vy == o.vy && vx == o.vx && vz == o.vz;
	}
	
	private void writeObject(java.io.ObjectOutputStream out) throws IOException{
		out.writeFloat(vx);
		out.writeFloat(vy);
		out.writeFloat(vz);
		out.writeInt(target);
		out.writeUnshared(stats);
	}
 
	private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException{
		vx = in.readFloat();
		vy = in.readFloat();
		vz = in.readFloat();
		target = in.readInt();
		stats = (Stats) in.readObject();
	}
}
